##################################################################
# File : /lua/maui/linktext.lua
# Description : Clickable Text
# Author : Neruz
##################################################################

local Text = import('/lua/maui/text.lua').Text
local UIUtil = import('/lua/ui/uiutil.lua')
local LayoutHelpers = import('/lua/maui/layouthelpers.lua')
local Bitmap = import('/lua/maui/bitmap.lua').Bitmap

LinkText = Class(Text) {

	SetLinkOptions = function(self, func, up, over)
		self:SetColor(up)
		self._upcolor = up
		self._overcolor = over
		self._onclickedfunc = func
	end,
	
	SetUnderlined = function(self, bool)
		if bool then
			self._underline = Bitmap(self)
    		LayoutHelpers.Below(self._underline, self, -3)
    		self._underline.Width:Set(self.Width())
    		self._underline.Height:Set(1)
    		self._underline:SetSolidColor(self._upcolor())
    	else
    		if self._underline then
    			self._underline:Destroy()
    		end
    	end
    end,
	
	HandleEvent = function(self, event)
		if event.Type == 'MouseEnter' then
			self:SetColor(self._overcolor)
			GetCursor():SetTexture(UIUtil.GetCursor('Loot'))
			if self._underline then
				self._underline:SetSolidColor(self._overcolor())
			end
		elseif event.Type == 'MouseExit' then
			self:SetColor(self._upcolor)
			if self._underline then
				self._underline:SetSolidColor(self._upcolor())
			end
			GetCursor():Reset()
		elseif event.Type == 'ButtonPress' then
			self:SetColor(self._upcolor)
			if self._underline then
				self._underline:SetSolidColor(self._upcolor())
			end
			self._onclickedfunc()
		elseif event.Type == 'ButtonRelease' then
			self:SetColor(self._overcolor)
			if self._underline then
				self._underline:SetSolidColor(self._overcolor())
			end
		end
	end,
}